# -*- coding: utf-8 -*-

import serial


NAME = 'com1'
ser1 = serial.Serial(NAME, 115200, timeout=2)

if ser1.isOpen():
    while True:
        data1 = ser1.readline().strip()
        # 判断是否为数字
        if data1.isdigit():
            value = int(data1)
            print("已接收到整数：%d" % value, type(value))
        else:
            print("接收到非整数数据：%s" % str(data1))
else:
    print("串口打开失败")
